<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 1.5.8">
<title>The demo setup (Cloud Foundry)</title>
<link rel="stylesheet" href="css/spring.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body class="article toc2 toc-left">
<div id="header">
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#the-demo-setup-cloud-foundry">The demo setup (Cloud Foundry)</a>
<ul class="sectlevel2">
<li><a href="#deploying-production-applications-to-pcf-dev">Deploying Production Applications to PCF Dev</a></li>
<li><a href="#running-prometheus-on-cf">Running Prometheus on CF</a></li>
<li><a href="#running-grafana-on-cf">Running Grafana on CF</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="the-demo-setup-cloud-foundry"><a class="link" href="#the-demo-setup-cloud-foundry">The demo setup (Cloud Foundry)</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>The demo uses two applications: <a href="https://github.com/spring-cloud-samples/github-webhook/">Github Webhook</a>
and <a href="https://github.com/spring-cloud-samples/github-analytics/">Github analytics code</a>. The following
image shows how these application communicate with each other:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="https://raw.githubusercontent.com/CloudPipelines/concourse/master/docs/images/demo/demo.png" alt="demo">
</div>
<div class="title">The overview of the demo: Github Webhook listens to HTTP calls and sends a message to Github Analytics</div>
</div>
<div class="paragraph">
<p>&#160;
&#160;</p>
</div>
<div class="paragraph">
<p>For the demo scenario we have two applications. <code>Github Analytics</code> and <code>Github Webhook</code>.
Let&#8217;s imagine a case where Github is emitting events via HTTP. <code>Github Webhook</code> has
an API that could register to such hooks and receive those messages. Once this happens
 <code>Github Webhook</code> sends a message by RabbitMQ to a channel. <code>Github Analytics</code> is
 listening to those messages and stores them in a MySQL database.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="https://raw.githubusercontent.com/CloudPipelines/concourse/master/docs/images/demo/demo_metrics.png" alt="demo metrics">
</div>
<div class="title">Gathering metrics: Github Analytics exposes metrics that are polled by Prometheus</div>
</div>
<div class="paragraph">
<p>&#160;
&#160;</p>
</div>
<div class="paragraph">
<p><code>Github Analytics</code> has its KPIs (Key Performance Indicators) monitored. In the case
of that application the KPI is number of issues.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="https://raw.githubusercontent.com/CloudPipelines/concourse/master/docs/images/demo/demo_alerting.png" alt="demo alerting">
</div>
<div class="title">Alerting over metrics: Grafana alerts Slack over Prometheus metrics</div>
</div>
<div class="paragraph">
<p>&#160;
&#160;</p>
</div>
<div class="paragraph">
<p>Let&#8217;s assume that if we go below the threshold of X issues then an alert should be
sent to Slack.</p>
</div>
<div class="sect2">
<h3 id="deploying-production-applications-to-pcf-dev"><a class="link" href="#deploying-production-applications-to-pcf-dev">Deploying Production Applications to PCF Dev</a></h3>
<div class="paragraph">
<p>In a real-world scenario, we would not want to automatically provision services such as
RabbitMQ, MySQL, or Eureka each time we deploy a new application to production. Typically,
production is provisioned manually (often by using automated solutions). In our case, before
you deploy to production, you can provision the <code>pcfdev-prod</code> space by using the
 <code>cf-helper.sh</code>. To do so, call the following script:</p>
</div>
<div class="exampleblock">
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ ./cf-helper.sh setup-prod-infra</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>The CF CLI:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Logs in to PCF Dev,</p>
</li>
<li>
<p>Targets the <code>pcfdev-prod</code> space</p>
</li>
<li>
<p>Sets up:</p>
<div class="ulist">
<ul>
<li>
<p>RabbitMQ (under the <code>rabbitmq-github</code> name)</p>
</li>
<li>
<p>MySQL (under <code>mysql-github-analytics</code> name)</p>
</li>
<li>
<p>Eureka (under <code>github-eureka</code> name)</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="running-prometheus-on-cf"><a class="link" href="#running-prometheus-on-cf">Running Prometheus on CF</a></h3>
<div class="paragraph">
<p>You can check out <a href="https://github.com/making/prometheus-on-PCF">Toshiaki Maki&#8217;s code</a> on how to automate Prometheus installation on CF.</p>
</div>
<div class="paragraph">
<p>Go to <a href="https://prometheus.io/download/" class="bare">https://prometheus.io/download/</a> and download the Linux binary. Then run the following command:</p>
</div>
<div class="exampleblock">
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">cf push cloud-pipelines-prometheus -b binary_buildpack -c './prometheus -web.listen-address=:8080' -m 64m</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Also, <code>localhost:9090</code> in <code>prometheus.yml</code> should be <code>localhost:8080</code>.</p>
</div>
<div class="paragraph">
<p>The file should resemble the following listing to work with the demo setup (change <code>github-analytics-cloud-pipelines.cfapps.io</code>
to your <code>github-analytics</code> installation).</p>
</div>
<div class="exampleblock">
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-yml hljs" data-lang="yml"># my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'codelab-monitor'

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first.rules"
  # - "second.rules"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=&lt;job_name&gt;` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ['localhost:8080']

  - job_name: 'demo-app'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    metrics_path: '/prometheus'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ['github-analytics-cloud-pipelines.cfapps.io']</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>A deployed version for the Cloud Pipelines demo is available <a href="https://cloud-pipelines-prometheus.cfapps.io/">here</a>.</p>
</div>
</div>
<div class="sect2">
<h3 id="running-grafana-on-cf"><a class="link" href="#running-grafana-on-cf">Running Grafana on CF</a></h3>
<div class="paragraph">
<p>You can check out <a href="https://github.com/making/cf-grafana">Toshiaki Maki&#8217;s code</a> to see how to automate Prometheus installation on CF.</p>
</div>
<div class="paragraph">
<p>Download the tarball from <a href="https://grafana.com/grafana/download?platform=linux" class="bare">https://grafana.com/grafana/download?platform=linux</a>
and set <code>http_port = 8080</code> in <code>conf/default.ini</code>. Then run the following the command:</p>
</div>
<div class="exampleblock">
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">cf push cloud-pipelines-grafana -b binary_buildpack -c './bin/grafana-server web' -m 64m</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>The demo uses Grafana Dashboard with an ID of <code>2471</code>.</p>
</div>
<div class="paragraph">
<p>A deployed version for the Cloud Pipelines demo is available <a href="https://cloud-pipelines-grafana.cfapps.io/">here</a></p>
</div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="js/highlight/styles/atom-one-dark-reasonable.min.css">
<script src="js/highlight/highlight.min.js"></script>
<script>hljs.initHighlighting()</script>
</body>
</html>